/*
 *  Copyright 2019-2020 Zheng Jie
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package me.zhengjie.modules.biz.domain;


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;

/**
 * @author Admin
 * @website https://eladmin.vip
 * @description /
 * @date 2023-03-03
 **/
@Entity
@Data
@Table(name = "hj_hazardous_chemicals")
public class HazardousChemicals implements Serializable {

    public static final int QI_CAI = 1;//器材
    public static final int BIAO_ZHUN_WU_ZHI = 2;//标准物质
    public static final int HUA_XUE_SHI_JI = 3;//化学试剂

    public boolean isQiCai() {
        return type == QI_CAI;
    }

    public boolean isHuaXueShiJi() {
        return type == HUA_XUE_SHI_JI;
    }

    public boolean isBiaoZhunWuZhi() {
        return type == BIAO_ZHUN_WU_ZHI;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "`id`")
    @ApiModelProperty(value = "id")
    private Integer id;

    @Column(name = "`name`")
    @ApiModelProperty(value = "名称")
    private String name;

    @Column(name = "`type`")
    @ApiModelProperty(value = "危化品类型")
    private Integer type;

    @Column(name = "`amount`")
    @ApiModelProperty(value = "危化品数量")
    private Float amount;

    @Column(name = "`lab_id`")
    @ApiModelProperty(value = "实验室")
    private Integer labId;

    @Column(name = "`note`")
    @ApiModelProperty(value = "备注")
    private String note;

    @Column(name = "`created_at`")
    @CreationTimestamp
    @ApiModelProperty(value = "createdAt")
    private Timestamp createdAt;

    @Column(name = "`is_deleted`")
    @ApiModelProperty(value = "是否删除")
    private Integer isDeleted;

    @Column(name = "`count_type`")
    @ApiModelProperty(value = "计数类型")
    private Integer countType;

    @Column(name = "`updated_at`")
    @UpdateTimestamp
    @ApiModelProperty(value = "updatedAt")
    private Timestamp updatedAt;

    @Column(name = "`bar_code`")
    @ApiModelProperty(value = "条形码")
    private String barCode;

    @Column(name = "`cabinet_id`")
    @ApiModelProperty(value = "存放化学品柜")
    private Integer cabinetId;

    @Column(name = "`measure_id`")
    @ApiModelProperty(value = "计量方式")
    private Integer measureId;

    @Column(name = "`danger_classes`")
    @ApiModelProperty(value = "危险等级")
    private Integer dangerClasses;

    @Column(name = "`capacity`")
    @ApiModelProperty(value = "规格")
    private Float capacity;

    @Column(name = "`weight`")
    @ApiModelProperty(value = "重量")
    private Float weight;

    @Column(name = "`status`")
    @ApiModelProperty(value = "状态")
    private Integer status;

    @Column(name = "`category`")
    @ApiModelProperty(value = "类型")
    private String category;

    @Column(name = "`unit`")//标准物质 1支, 2瓶
    @ApiModelProperty(value = "单位")
    private Integer unit;

    @Column(name = "`storage`")
    @ApiModelProperty(value = "仓库")
    private Integer storage;

    @Column(name = "`location`")
    @ApiModelProperty(value = "位置")
    private String location;

    @Column(name = "residue")
    @ApiModelProperty(value = "剩余量")
    private Float residue;

    @Column(name = "grade")
    @ApiModelProperty(value = "级别")
    private String grade;

    @Column(name = "is_audit")
    @ApiModelProperty(value = "是否需要审批")
    private Integer isAudit;

    @Column(name = "number")
    @ApiModelProperty(value = "编号")
    private String number;

    @Column(name = "batch_number")
    @ApiModelProperty(value = "批号")
    private String batchNumber;

    @Column(name = "ingredient_data")
    @ApiModelProperty(value = "成分")
    private String ingredientData;

    @Column(name = "matrix")
    @ApiModelProperty(value = "基体")
    private String matrix;

    @Column(name = "attenuation")
    @ApiModelProperty(value = "稀释方法")
    private String attenuation;

    @Column(name = "expiration_date")
    @ApiModelProperty(value = "有效期")
    private Timestamp expirationDate;

    @Column(name = "file_url")
    @ApiModelProperty(value = "证书")
    private String fileUrl;

    @Column(name = "is_past_due")
    @ApiModelProperty(value = "是否过期")
    private Integer isPastDue;

    @Column(name = "is_apply")
    @ApiModelProperty(value = "是否需要申领")
    private Integer isApply;

    public void copy(HazardousChemicals source) {
        BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true));
    }

    public float getInputResidue() {
        if (unit == 1 && isHuaXueShiJi()) {
            return capacity * 1000;
        }

        return capacity;
    }

    //是否是一个物品一个代码
    public boolean isSingleCodePerObject() {
        return true;
    }
}
